// pages/print/printer/printer.js
var utils = require("../../../utils/utils.js");
const app = getApp();
Page({

    /**
     * 页面的初始数据
     */
    data: {
        chooseIndex:2,
        option:{}
    },
    chooseClass(e){
        var index = e.currentTarget.dataset.index;
        this.setData({
            chooseIndex:index
        })
    },
    add(){
      this.pdfs(0);
    },
    save(){
      this.pdfs(1);
    },
    pdfs(num){
      var that = this;
      that.selectComponent("#loading").showLoadingCus('处理中');
      utils.request('convert/pdfNarrow',{'num':that.data.chooseIndex,'pdfUrl':that.data.option.path}, function (res) {
        that.selectComponent("#loading").hideLoadingCus();
        if(res.data.code==200){
          if(num==0){
            wx.navigateTo({
                url: '/pages/my/pdfsee/pdfsee?url='+res.data.data.url+'&name='+that.data.option.name
            })
          }
          if(num==1){
            wx.navigateTo({
              url: '/pages/print/list/list?code=' + that.data.option.code + '&name=' + that.data.option.name + '&path=' + res.data.data.url + '&pageNum='+res.data.data.pageNum+'&fileUrl='+res.data.data.url+'&serviceMainId='+that.data.option.serviceMainId+'&serviceSubtypeId='+that.data.option.serviceSubtypeId+'&tagFloor='+that.data.option.tagFloor+'&orientation='+ res.data.data.orientation
            })
          }
        }else{
          utils.toast(res.data.msg)
        }
      })
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        var that = this;
        that.setData({
            option:options
        })
        wx.getSystemInfo({
            success: (result) => {
              var model = result.model;
              if (model == 'iPhone X') {
                that.setData({
                  pdbottom: '68',
                  lineH: 128
                })
              } else {
                that.setData({
                  pdbottom: '40',
                  lineH: 100
                })
              }
            },
          })
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {

    }
})